let num:number;
num=123;
console.log(num)
// 数字类型
let num1:number=456;
console.log(num1)

// 字符串类型
let str1:string='web';
let str2:string='asd';
let str3:string;
// str3=str1+str2
str3=str1+num1
console.log(str1,str2,str3)
// 布尔类型
let bool:boolean=true;
console.log(bool);

let str4:string,num2:number,bool2:boolean;
str4='123'
num2=456;
bool2=false;
console.log(str4,num2,bool2);

// 字面量
let yy:'ysx';
yy='ysx'
console.log(yy);
// 联合类型
let bb:'ysx' | 'mjl' | 'jyn';
bb='mjl';
console.log(bb);

// any
let ss:any;
ss='213'
// let xx:string;
// xx=ss 可以赋值
// console.log(xx)
console.log(ss);

// unknown
let mm:unknown;
mm=123;
mm=true
// let oo:string;
// 00=mm  不能赋值
console.log(mm)

// void 表示函数的返回值  undefined  null
function fun(a:number,b:number):number{
    return a+b;
}
console.log(fun(1,2))

// 对象
let obj:{name:string,age:number};
obj={
    name:'jack',
    age:18 
}
console.log(obj)

let obj2:{name:string,age:number,sex?:string}
obj2={
    name:'qwe',
    age:55,
    sex:'男'
}
console.log(obj2);
let obj3:{name:string,age:number,[ysx:string]:unknown};
obj3={
    name:'ty',
    age:454,
    hobby:'打游戏'
}
obj3.height=123

console.log(obj3)
// array
let arr:string[];
arr=['sas','sd']
console.log(arr);

let arr2:Array<number>;
arr2=[1,5,2,3];
console.log(arr2)

let arr3:Array<string>;
arr3=['sds','sds']
console.log(arr3);

// 元组
let arr4:[string,number,boolean];
arr4=['qwe',233,false];
console.log(arr4);

// 枚举
enum color{
    pink,
    blue,
    green
}
let ysx:color=color.pink;
console.log(ysx)
console.log(color[0],color[1],color[2]);

// 类型联合
// let qq:'ysx'| 'mjl'| 'jyn'| 123;
// qq='ysx';
// qq=123;

function boo(a:string | number,b:number):void{
 
    console.log(a,b)
}
boo('12',45);

// 类型断言
function buy(x:number | string){
    if((<string>x).length){
        console.log(111)
    }else{
        console.log(222);
        return x.toString().length;
    }
}
console.log(buy(122))

// 类型推断
let toy='qwyi';
// 字符串类型
let toyyA
// any 任意数据类型